/*     */ package com.zimbra.cs.mailclient.pop3;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Pop3Capabilities
/*     */ {
/*     */   private Map<String, List<String>> capabilities;
/*     */   public static final String TOP = "TOP";
/*     */   public static final String USER = "USER";
/*     */   public static final String STLS = "STLS";
/*     */   public static final String SASL = "SASL";
/*     */   public static final String RESP_CODES = "RESP-CODES";
/*     */   public static final String LOGIN_DELAY = "LOGIN-DELAY";
/*     */   public static final String PIPELINING = "PIPELINING";
/*     */   public static final String EXPIRE = "EXPIRE";
/*     */   public static final String UIDL = "UIDL";
/*     */   public static final String IMPLEMENTATION = "IMPLEMENTATION";
/*     */   
/*     */   public static Pop3Capabilities read(ContentInputStream is)
/*     */     throws IOException
/*     */   {
/*  48 */     Pop3Capabilities caps = new Pop3Capabilities();
/*  49 */     caps.readCapabilities(is);
/*  50 */     return caps;
/*     */   }
/*     */   
/*     */   private Pop3Capabilities() {
/*  54 */     this.capabilities = new HashMap();
/*     */   }
/*     */   
/*     */   private void readCapabilities(ContentInputStream is) throws IOException {
/*     */     String line;
/*  59 */     while ((line = is.readLine()) != null) {
/*  60 */       String[] words = line.split(" ");
/*  61 */       if (words.length > 0) {
/*  62 */         String key = words[0];
/*  63 */         List<String> params = (List)this.capabilities.get(key);
/*  64 */         if (params == null) {
/*  65 */           params = new ArrayList();
/*  66 */           this.capabilities.put(key.toUpperCase(), params);
/*     */         }
/*  68 */         for (int i = 1; i < words.length; i++) {
/*  69 */           params.add(words[i]);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public boolean hasCapability(String cap) {
/*  76 */     return this.capabilities.containsKey(cap.toUpperCase());
/*     */   }
/*     */   
/*     */   public boolean hasCapability(String cap, String param) {
/*  80 */     if (param == null) {
/*  81 */       return hasCapability(cap);
/*     */     }
/*  83 */     List<String> params = getParameters(cap);
/*  84 */     return (params != null) && (params.contains(param));
/*     */   }
/*     */   
/*     */   public List<String> getParameters(String cap) {
/*  88 */     return (List)this.capabilities.get(cap.toUpperCase());
/*     */   }
/*     */   
/*     */   public String toString() {
/*  92 */     StringBuilder sb = new StringBuilder("{");
/*  93 */     Iterator<Map.Entry<String, List<String>>> entries = this.capabilities.entrySet().iterator();
/*     */     
/*  95 */     while (entries.hasNext()) {
/*  96 */       Map.Entry<String, List<String>> e = (Map.Entry)entries.next();
/*  97 */       sb.append((String)e.getKey());
/*  98 */       Iterator<String> params = ((List)e.getValue()).iterator();
/*  99 */       if (params.hasNext()) {
/* 100 */         sb.append("=\"").append((String)params.next());
/* 101 */         while (params.hasNext()) {
/* 102 */           sb.append(' ').append((String)params.next());
/*     */         }
/* 104 */         sb.append('"');
/*     */       }
/* 106 */       if (entries.hasNext()) {
/* 107 */         sb.append(',');
/*     */       }
/*     */     }
/* 110 */     sb.append('}');
/* 111 */     return sb.toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/pop3/Pop3Capabilities.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */